tex, string, and separator options for units#1447
Conversation
edd0da7 to
9b88415
Compare
9b88415 to
940409b
Compare
drgrice1
left a comment
There was a problem hiding this comment.
This satisfies my initial request to make the properties centralized and defined in Units.pm, but will not work for what @dpvc asked. That is so that custom units can also take advantage of the new features. For this the addUnit method will need some more modification. Also the copies of the %context::Units::Context::DISPLAY hash made on line 958 for the context::Units::Unit package and line 1442 for the context::Units::NumberWithUnit package are going to be an issue for that as well. If the addUnit method modifies the %context::Units::Context::DISPLAY hash, then the copies will not be modified appropriately. Making those copies is also not particularly efficient. Those should be references instead.
This implements one of the suggestions from @dpvc in #1437, and replaces that pull request.
Units.pmcan havestring,tex,string_separator, andtex_separatorproperties.micronto be a named unit instead of an alias.stringproperty is used when the unit or its aliases are printed as a string.stringproperty needs to use a string that can actually be printed in hardcopy. There is a comment about this in the file above where the big units hash is defined.Compute(), make sure that any allstringproperties are also unit names.texproperty is used when the unit or its aliases are printed as tex.tex_separatorproperty are only used when the unit is not part of a larger fractional unit, and the unit is the first unit following a number. Otherwise a space is used, as has been the case. For example,180°and180° s, but180 s °(except as tex).string_separatorproperty is similar, except it is also used even when there is a larger fractional unit. For example,180°/s.degis usingtex_separatorandstring_separator, with each set to the empty string. I considered doing this withdegFanddegC, but Google tells me there should be a space for those units for scientific publications.contextUnits.plwas adding aliases forL(liter,liters,litre, andlitres). It was cleaner to move those over toUnits.pm. If there was a reason they were not already inUnits.pm, I could move them back.One thing that could still be improved, is that for string production, the spaces that are used in between numbers and units (when
string_separatoris not set), or between units and units should be nonbreaking spaces. I tried things that I though should work, but did not work for one reason or another. So that can be addressed in some future PR.Try the problem from #1437 for some basic testing. Although you may want to also try with some more complicated units that have unit products and quotients.